package forum.server.persistence;

import java.util.Vector;

import forum.server.domain.*;
import forum.server.exceptions.*;



public interface DataManipulatorInt {   
        /**
         * increases the count of the online guests. 
         * @throws DatabaseException on database error.
         */
        public void incGuestCount() throws DatabaseException;
        /**
         * decreases the count of the online guests. 
         * @throws DatabaseException on database error.
         */
        public void decGuestCount() throws DatabaseException;
        /**
         * gets the online guests count.
         * @throws DatabaseException on database error.
         * @return the guests count.
         */
        public int getGuestCount() throws DatabaseException;
        /**
     * save that the user is online.
     * @param username the username to connect
     * @throws DatabaseException on database error.
     */
        public void connectUser(String username) throws DatabaseException;
        /**
     * save that the user is offline.
     * @param username the username to disconnect
     * @throws DatabaseException on database error.
     */
        public void disconnectUser(String username) throws DatabaseException;
        /**
     * gets the currently connected users.
     * @return the connected users.
     * @throws DatabaseException on database error.
     */
        public Vector<String> getConnectedRegisteredUsers() throws DatabaseException;
        /**
     * init the db.
     */
        public void resetDataBase() throws DatabaseException;
    /**
     * This function returns all the posts from the file.
     * @throws DatabaseException on database error.
     */
    public Vector<Post> getReplies(int postId) throws DatabaseException;
    
    /**
     * Returns all the posts without a father=> parentId=-1
     * @throws DatabaseException on database error.
     */
    public Vector<Post> getPosts() throws DatabaseException;
    
    /**
     * Deletes the post and it's replies from the db .     
     * @param postId the post id to delete from the db.
     * @throws DatabaseException on database error.
     */
    public void deletePost(int postId) throws DatabaseException;

    /**
     * Deletes the user from the db.
     * @param username the user to delete.
     * @throws DatabaseException on database error.
     * @throws NoSuchUserException
     */
    public void deleteUser(String username) throws DatabaseException, NoSuchUserException;

    /**
     * Returns the post whose id is postId.     
     * @param postId the post id to get from the db.
     * @throws DatabaseException on database error.
     * @throws NoSuchPostException
     */
    public Post getPost(int postId) throws DatabaseException, NoSuchPostException;

    /**
     * Returns the user from the db.     
     * @param username the user to get from the db.
     * @throws DatabaseException on database error.
     * @throws NoSuchUserException
     */
    public LoggedInUser getUser(String username) throws DatabaseException, NoSuchUserException;
    
    /**
     * Adds a user to the db.     
     * @param user the user to add to the db.
     * @throws DatabaseException on database error.
     */
    public void addUser(LoggedInUser user) throws DatabaseException;

    /**
     * Returns true if a user with user as a username.     
     * @param user the user name.
     * @throws DatabaseException on database error.
     */
    public boolean isUserExists(String user) throws DatabaseException;

    /**
     * Returns the number of users registered in the db.
     * does not include guests, includes moderators and admins.
     * @throws DatabaseException on database error.
     */
    public int countUsers() throws DatabaseException;

    /**
     * Adds a reply to the db.     
     * @param fatherId the id of the parent to the reply.
     * @param reply the reply to add to the post.
     * @throws DatabaseException on database error.
     * @return the post id of the reply.
     */
    public int addReply(int fatherId, Post reply) throws DatabaseException;
    
    /**
     * @param username
     * @return
     * @throws DatabaseException on database error.
     */
    public Moderator promoteModerator(String username)
            throws DatabaseException, NoSuchUserException;

    /**
     * @param username
     * @return
     * @throws DatabaseException on database error.
     */
    public LoggedInUser demoteModerator(String username)
            throws DatabaseException, NoSuchUserException;

    /**
     * This function adds a main post/topic to the forum's db .
     * the parentId of the post is set to -1.     
     * @param p the post to add to the db.
     * @throws DatabaseException on database error.
     * @return the post id of the new post. 
     */
    public int addPost(Post p) throws DatabaseException;

    /**
     * This function sets the post content of the post with id postId to be pc.
     * @param postId identifier of the post to change.
     * @param pc the new content of the post.
     * @throws DatabaseException on database error.
     */
    public void modifyPost(int postId, PostContent pc) throws DatabaseException;
    
    /**
     * @return the max postId in the db +1.
     * @throws DatabaseException on database error.
     */
    public int generateNewPostId() throws DatabaseException;
    /**
     * 
     * @return all the users in the system.
     * @throws DatabaseException on database error.
     */
    public Vector<LoggedInUser> getAllUsers() throws DatabaseException;
    /**
     * @return all the users that can be promoted - non moderators and not admin.
     * @throws DatabaseException on database error.
     */
    public Vector<LoggedInUser> getAllUsersForPromotion() throws DatabaseException;
    /**
     * @return all the moderators.
     * @throws DatabaseException on database error.
     */
    public Vector<Moderator> getAllModerators() throws DatabaseException;
    
}
